package com.swust.mapper;

import com.swust.po.Order;
import com.swust.po.OrderDetail;
import com.swust.po.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrderMapper {
    @Select("select * from mybatis02.order")
    @Results({
            @Result(column = "user_id" , property = "user",javaType = User.class,one =@One(select = "com.swust.mapper.UserMapper.findUserById",fetchType = FetchType.LAZY))
    })
    List<Order> findOrderAndUserLazy();
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column="user_id",property = "userId"),
            @Result(property = "user",column = "user_id",javaType = User.class,
                    one = @One(select ="com.swust.mapper.UserMapper.findUserById",fetchType = FetchType.LAZY)),
            @Result(property="orderDetails",javaType = List.class,column="id",
                    many = @Many(select = "com.swust.mapper.OrderDetailMapper.findByOrderId",fetchType = FetchType.LAZY))
    })
    @Select("SELECT * FROM mybatis02.`order`")
    List<Order> findOrderAndOrderDetails();

}
